package com.shenmazong.serveruserapi.controller;

import com.shenmazong.utils.ResponseResult;
import com.shenmazong.serveruserapi.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(tags = "用户管理API")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long")
    })
    @PostMapping(value = "/getUserById")
    public ResponseResult getUserById(@RequestParam("userId") Integer userId) {
        return userService.getUserById(userId);
    }

    /**
     * TODO sendSms 发送手机验证码(注册)
     * 暂时有个漏洞，不能够防止被刷接口
     * @param mobile
     * @return
     */
    @ApiOperation(value = "发送验证码", notes = "用户第一次登录需要发送验证码")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mobile", value = "用户手机号", required = true, dataType = "String")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "请求成功"),
            @ApiResponse(code = 1001, message = "参数错误"),
            @ApiResponse(code = 1002, message = "内部错误")
    })
    @PostMapping(value = "/sendSms")
    public ResponseResult sendSms(@RequestParam("mobile") String mobile) {
        return userService.sendSms(mobile);
    }

    /**
     * TODO verifyCode 实现验证码登录
     * @param mobile
     * @param vcode
     * @return
     */
    @ApiOperation(value = "校验验证码", notes = "通过校验验证码实现登录功能")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mobile", value = "用户手机号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "vcode", value = "验证码", required = true, dataType = "int", example = "0")
    })
    @PostMapping(value = "/verifyCode")
    public ResponseResult verifyCode(@RequestParam("mobile") String mobile,
                             @RequestParam("vcode") Integer vcode) {
        return userService.verifyCode(mobile, vcode);
    }

    /**
     * TODO quickLogin 快捷登录
     * @param userId
     * @param userToken
     * @return
     */
    @ApiOperation(value = "快捷登录", notes = "使用已有的token获取新的token")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", example = "0"),
            @ApiImplicitParam(name = "userToken", value = "过期token", required = true, dataType = "String")
    })
    @PostMapping(value = "/quickLogin")
    public ResponseResult quickLogin(@RequestParam("userId") Integer userId,
                             @RequestParam("userToken") String userToken) {
        return userService.quickLogin(userId, userToken);
    }

    /**
     * TODO uploadHead 上传头像图片
     * @param userId
     * @param file
     * @return
     */
    @ApiOperation(value = "头像上传", notes = "用户上传更新自己的头像")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", example = "0")
    })
    @PostMapping(value = "/uploadHead", headers = "content-type=multipart/form-data")
    public ResponseResult uploadHead(@RequestParam("userId") Integer userId,
                             @RequestParam("uploadFile") MultipartFile file) {
        return userService.uploadHead(userId, file);
    }

    /**
     * TODO setUserInfo 修改用户信息
     * @param userId
     * @param nickName
     * @param sex
     * @return
     */
    @ApiOperation(value = "修改用户信息", notes = "用户修改自己的信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", example = "0"),
            @ApiImplicitParam(name = "nickName", value = "用户昵称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sex", value = "用户性别", required = true, dataType = "int", example = "0"),
    })
    @PostMapping(value = "/setUserInfo")
    public ResponseResult setUserInfo(@RequestParam("userId") Integer userId,
                              @RequestParam("nickName") String nickName,
                              @RequestParam("sex") Integer sex) {
        return userService.setUserInfo(userId, nickName, sex);
    }

    /**
     * TODO setUserStatus 修改用户状态
     * @param userId
     * @param status
     * @return
     */
    @ApiOperation(value = "锁定用户", notes = "锁定或者解锁用户")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", example = "0"),
            @ApiImplicitParam(name = "status", value = "锁定状态:0解锁1锁定", required = true, dataType = "int", example = "0")
    })
    @PostMapping(value = "/setUserStatus")
    public ResponseResult setUserStatus(@RequestParam("userId") Integer userId,
                                @RequestParam("status") Integer status) {
        return userService.setUserStatus(userId, status);
    }

    //-- 每天注册用户数
    //-- 每天登录数
    //-- 每天点赞量
    //-- 每天关注量
}
